package nl.depository.pim.pages.types;

import nl.depository.pim.entities.EditorText;

import org.apache.tapestry5.Field;
import org.apache.tapestry5.FieldTranslator;
import org.apache.tapestry5.MarkupWriter;
import org.apache.tapestry5.ValidationException;
import org.apache.tapestry5.annotations.Component;
import org.apache.tapestry5.annotations.Environmental;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.corelib.components.TextArea;
import org.apache.tapestry5.internal.translator.AbstractTranslator;
import org.apache.tapestry5.services.FormSupport;
import org.apache.tapestry5.services.PropertyEditContext;

public class EditorTextType
{
	@Property
	@Environmental
	private PropertyEditContext context;
	
	@Component(parameters = {"value=context.propertyValue", "label=prop:context.label", "clientId=prop:context.propertyId", "annotationProvider=context",
			"translate=prop:translator"})
	private TextArea textarea;
	
	public FieldTranslator<?> getTranslator()
	{
		return context.getTranslator(textarea);
	}
	
	public static class Translator extends AbstractTranslator<EditorText>
	{
		public Translator()
		{
			super("editorText", EditorText.class, "editorText");
		}
		
		public String toClient(EditorText value)
		{
			return value.toString();
		}
		
		public EditorText parseClient(Field field, String clientValue, String message) throws ValidationException
		{
			return null;
		}
		
		public void render(Field field, String message, MarkupWriter writer, FormSupport formSupport)
		{
		}
	}
}